import {ref, computed} from 'vue'
import {defineStore} from 'pinia'

export const userStore = defineStore('user', () => {
    const user = ref(null)
    const userInfo = computed(() => user.value)

    function updateUser(u) {
        user.value = u
    }

    // 重置token
    function $reset() {
        user.value = null
    }

    return {user, userInfo, updateUser, $reset}
}, {
    persist: {
        key: 'user', //存储名称
        storage: sessionStorage, // 存储方式
    }
})
